// mircoApp/new-auction/new_auction_billing/new_auction_billing.js
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    show: false,
    pageTitle: "",
    typeInd: 0,
    list: [],
    show_Detail: false,
    detailInfo: [],
    tag: "",

    page: 1,
    total_page: 0,
    isLoadMore: true
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    if (options.tag) {
      this.setData({
        tag: options.tag
      })
    }
    if (this.data.tag == "new_auction_rechargeDetail") {
      wx.setNavigationBarTitle({
        title: '充值明细',
      })
    } else {
      wx.setNavigationBarTitle({
        title: '账单明细',
      })
      this.getTypeList();
    }
    let language = wx.getStorageSync("langIndex");
    this.setData({
      language: language.en
    })
    this.init();
    this.getList();
  },
  tapList(e) {
    let {
      item
    } = e.currentTarget.dataset;
    if (this.data.tag == "new_auction_rechargeDetail") {
      this.detailInfo = item;
      this.show_Detail = true;
      this.setData({
        show_Detail: true,
        detailInfo: item
      })
    }
  },
  closePopup_detail() {
    this.setData({
      show_Detail: false,
      detailInfo: []
    })
  },
  tapPopup(e) {
    let {
      index
    } = e.currentTarget.dataset;
    this.setData({
      typeInd: index,
      show: false,
    })
    this.init();
    this.getList();
  },
  init() {
    this.setData({
      page: 1,
      isLoadMore: true,
      total_page: 0
    })
  },
  closeShow() {
    this.setData({
      show: false
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {
    this.getMoreData();
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  },
  showPopup() {
    this.setData({
      show: true
    })
  },
  async getTypeList() {
    let {
      data
    } = await app._postNetWork({
      url: app.getNetAddresss("plugin.new-auction.frontend.money"),
    })
    if (data.result) {
      data.data.type_name[0] = "全部"
      this.setData({
        type_name: data.data.type_name,
      })
    } else {
      app.tips(data.msg)
    }
  },
  async getList() {
    let json = {};
    if (this.data.typeInd) {
      json.money_type = this.data.typeInd;
    }
    if (this.data.tag == "new_auction_rechargeDetail") {
      json.money_type = "6";
    }
    let {
      data
    } = await app._postNetWork({
      url: app.getNetAddresss("plugin.new-auction.frontend.money"),
      data: json
    })
    if (data.result) {
      this.setData({
        list: data.data.data,
        isLoadMore: true,
        total_page: data.data.last_page
      })
    } else {
      app.tips(data.msg);
    }
  },
  async getMoreData() {
    if (!this.data.isLoadMore) return;
    this.data.isLoadMore = false;
    if (this.data.page >= this.data.total_page) {
      return
    } else {
      this.setData({
        page: this.data.page + 1
      })
      let json = {
        page: this.data.page,
        money_type: this.data.typeInd
      }
      if (this.data.tag == 'new_auction_rechargeDetail') {
        json.money_type == "6"
      }
      let {
        data
      } = await app._postNetWork({
        url: app.getNetAddresss("plugin.new-auction.frontend.money"),
        data: json
      })
      if (data.result) {
        this.setData({
          list: this.data.list.concat(data.data.data)
        })
        this.data.isLoadMore = true;
      } else {
        app.tips(data.msg)
        this.setData({
          page: this.data.page - 1,
          isLoadMore: false
        })
      }
    }
  }
})